#!/usr/bin/env python
# coding:utf-8

class symbol_table():
    """
    Class for symbol_table

    Intend usage:

    # Free clients from inputing ugly id..

    users['#3']  => 158946513 # user_id
    groups['#3']  => 11234 # group_id
    weibos['#3']  => 11234 # weibo_id

    # should it be update when displaying?
    """

    users = {
    }

    groups = {
    }

    weibos = {
    }

    comments = {
    }

    uid = 0 

    @classmethod
    def set_uid(cls, _uid):
        cls.uid = _uid

    @classmethod
    def clear_users(cls):
        cls.users = {}

    @classmethod
    def clear_groups(cls):
        cls.groups = {}

    @classmethod
    def clear_weibos(cls):
        cls.weibos = {}

    @classmethod
    def clear_comments(cls):
        cls.comments = {}

    @classmethod
    def get_user(cls, u):
        "Wrapper function to avoid exception"
        if u in cls.users:
            return cls.users[u]
        else:
            return None

    @classmethod
    def get_group(cls, g):
        "Wrapper function to avoid exception"
        if g in cls.groups:
            return cls.groups[g]
        else:
            return None

    @classmethod
    def get_weibo(cls, w):
        "Wrapper function to avoid exception"
        if w in cls.weibos:
            return cls.weibos[w]
        else:
            return None

    @classmethod
    def get_comment(cls, c):
        "Wrapper function to avoid exception"
        if c in cls.comments:
            return cls.comments[c]
        else:
            return None 
        
